package com.tjmc.nsia.core.utils;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author Luc
 * @version 1.0
 * @date 2024-06-07 12:52
 */
public class HttpUtils {

    private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);


    public static String sendGet(String url, String param) {
        String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
        logger.info("sendGet - {}", urlNameString);

        String result = HttpRequest.get(urlNameString).header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
                .header(Header.ACCEPT, "*/*")
                .header(Header.CONNECTION, "Keep-Alive")
                .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
                .execute().body();
        logger.info("recv - {}", result);
        return result;
    }


    public static String sendPlainPost(String url, Map<String, Object> params) {
        logger.info("sendPlainPost - {}", url);
        String response = HttpUtil.post(url, params);
        logger.info("recv - {}", response);
        return response;
    }
}
